package su.msk.jet.team01.chatik.server.commands.authorized;

import su.msk.jet.team01.chatik.server.commands.Command;
import su.msk.jet.team01.chatik.server.data.Client;

public abstract class AuthorizedCommand extends Command {

	private static final String CLIENT_INFO_MSG_NEED_AUTH = "Authorize yourself. Use /name command.";

	protected AuthorizedCommand(final String name, final int argsCount) {
		super(name, argsCount);
	}

	public AuthorizedCommand(String name, int minArgsCount, int maxArgsCount) {
		super(name, minArgsCount, maxArgsCount);
	}

	@Override
	public final void doExecute(final Client client, final String[] args) {
		if (client.getName().isEmpty()) {
			client.send(CLIENT_INFO_MSG_NEED_AUTH);
			return;
		}

		executeAuthorized(client, args);
	}

	public abstract void executeAuthorized(final Client client,
			final String[] args);

}
